export function timeAgo(timestamp) {
	// 确保传入的是毫秒级时间戳
	const inputTimestamp = Number(timestamp);
	const now = Date.now();
	const diff = now - inputTimestamp;

	// 定义时间单位（毫秒）
	const minute = 60 * 1000;
	const hour = 60 * minute;
	const day = 24 * hour;
	const month = 30 * day;
	const year = 12 * month;

	// 分钟判断
	if (diff < hour) {
		const minutes = Math.floor(diff / minute);
		return minutes > 0 ? `${minutes}分钟前` : '刚刚';
	}

	// 小时判断
	if (diff < day) {
		const hours = Math.floor(diff / hour);
		return `${hours}小时前`;
	}

	// 天数判断
	if (diff < month) {
		const days = Math.floor(diff / day);
		return `${days}天前`;
	}

	// 月份判断
	if (diff < year) {
		const months = Math.floor(diff / month);
		return months > 3 ? null : `${months}个月前`;
	}

	// 超过一年
	return null;
}